
<template>
    <up-popup :show="show" mode="center" round="6"  @close="close" @open="open">
        <view class="u-popup-slot">
            <view class="form">
                <view class="offer">
            
            报价：
            <up-input
              placeholder="请输期望的单价"
              type="number"
              v-model="price"
             
            >
            </up-input>
           </view>
            <view class="offer_num">
                数量：
                <up-input
              placeholder="请输入期望的数量"
              type="number"
              v-model="num"
            >
            </up-input>
            </view>
            </view>
            <view class="footer">
              <view  class="mybutton"> <up-button  type="primary"  @click="confirm">确认</up-button></view>
              <view class="mybutton"><up-button  type="primary"   @click="cancel">取消</up-button></view>
            </view>
			</view>
	</up-popup>
</template>


<script setup lang="ts">
import { useCurrentServe } from '@/stores/models/server';
import { http } from '@/utils/http';
import type { OfferWinProps } from '@/utils/page_types';
import { ref } from 'vue';  
  const show = ref(true);  
  const props = defineProps<OfferWinProps>()
  const price = ref('');
  const num  =ref('1')
  const serverStore  =  useCurrentServe();
  function open() {  
    show.value = true; 
    props.onOpen(); 
  }  
    
  function close() {  
    show.value = false;  
    props.onClose();
  } 

  
 const confirmOffer=async ()=>{
   const data=await http<null>({
		url:"/offer",
		data:{
			sdInfoId:props.infoId,
      sdInfoUserOpenID:props.infoOpenId,
			price:Number(price.value),
			type:Number(props.type),
      number:Number(num.value),
      serverId:serverStore.serverId
		},
		method:"POST"
	 });
	 console.log("confirmOffer",data)
	 
 }

  const confirm =()=>{
     console.log("cofirm",props.infoId, price.value,num.value)
     if(!uni.$u.test.amount(price.value)){
        uni.$u.toast('请输入正确的金额')
        return
     }
     if(!uni.$u.test.digits(num.value)||parseInt(num.value)>10000){
        uni.$u.toast('请输入正确的数量,不能超过1万!')
        return
     }
     confirmOffer();
     close();
  }

  const cancel =()=>{
     console.log("cancel")
     close();
  }
</script>



<style lang="scss" scoped>
.u-popup-slot {
		width: 720rpx;
		height: 220px;
		display: flex;
        flex-direction: column;
        border-radius: 8px;
        
	}
    .form{
        display: flex;
        flex-direction: column;
        margin-top: 30px;
        margin-left: 30px;
    }
    .offer{
        width: 90%;
        display: flex;
        align-items: center;
        margin-bottom: 20px;
       
    }

    .offer_num{
        width: 90%;
        display: flex;
        align-items: center;
    }
    .footer{
        display: flex;
        margin-top: 30px;
        justify-content: space-around;
    }
    .mybutton{
        width: 100px;
        

    }
</style>
